<?php
declare (strict_types = 1);

namespace app\controller\api;

use app\BaseController;
use think\Request;

class Goods extends BaseController
{

    // 商品列表
    public function list()
    {
        $time = time();
        $page = $this->request->param('page',0);
        $page_size = $this->request->param('page_size',20);
        $data = [
            'time' => $time,
            "page"=> $page,
            "page_size"=> $page_size,
            "sort"=> "add_time",
            "sort_type"=> "desc"
        ];
        $sign = $this->getSignature($data,config('app.APIKEY'));
        $param = [
            "api_id"=> config('app.APIID'),
            "sign"=> $sign,
            "data"=> $data,
        ];

        $url = 'http://main.miniappss.com/terminal/api.goods/getGoodsList';
        $res = $this->curlPost($url,$param);
        if(isset($res['code']) && $res['code'] != 200){
            return $this->error([],$res['msg'],$res['error_code']);
        }
        return $this->success($res['data'],$res['msg']);
    }

    // 商品详情
    public function getGoodsInfo()
    {
        $sku = $this->request->param('sku');
        $library = $this->request->param('library');
        $time = time();
        $data = [
            'time' => $time,
            "sku"=> $sku,
            "library"=> $library,
            "queryExts"=> "attribute,swiper",
        ];
        $sign = $this->getSignature($data,config('app.APIKEY'));
        $param = [
            "api_id"=> config('app.APIID'),
            "sign"=> $sign,
            "data"=> $data,
        ];
        $url = 'http://main.miniappss.com/terminal/api.goods/getGoodsInfo';
        $res = $this->curlPost($url,$param);
        if(isset($res['code']) && $res['code'] != 200){
            return $this->error([],$res['msg'],$res['error_code']);
        }
        return $this->success($res['data'],$res['msg']);
    }


}
